home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / sphigs / sph_srgp.lha / srgp / src / srgp_state.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-09  |  5.0 KB  |  255 lines

  1. #include "HEADERS.h"
  2. #define SRGP_BOSS
  3. #include "srgplocal.h"
  4.  
  5. static char message[] =  "Unable to open the SRGP logfile!";
  6.  
  7. int SRGP_errorOccurred = 0;
  8.  
  9. errorHandlingMode srgp__curErrHndlMode = FATAL_ERRORS;
  10.  
  11.  
  12.  
  13. /** SRGP_tracing
  14. **/
  15. void
  16. SRGP_tracing (boolean please_trace)
  17. {
  18.  
  19.    if ( ! SRGP_logStream) {
  20.       /* LOGGING FILE IN LINE-BUFFERED MODE. */
  21.       if (SRGP_logStream = fopen ("SRGPlogfile", "w")) 
  22. #ifdef sun
  23.      setvbuf (SRGP_logStream, NULL, _IOLBF, 512);
  24. #else
  25.       {}
  26. #endif
  27.       else {
  28. #ifdef THINK_C
  29.      ReportSpecialError (message, NON_FATAL);
  30.          return;  /* we can't enable it, but we can continue! */
  31. #else
  32.      fprintf (stderr, "%s\n", message);
  33.      exit (1);
  34. #endif
  35.       }
  36.    }
  37.  
  38.    SRGP_trace (SRGP_logStream, "---- TRACE DISABLED\n");
  39.    srgp__traceDisabled = ! please_trace;
  40.    SRGP_trace (SRGP_logStream, "++++ TRACE ENABLED\n");
  41. }
  42.  
  43.  
  44. void
  45. SRGP_disableDebugAids ()
  46. {
  47.    srgp__userDebugAidsDisabled = TRUE;
  48. }
  49.  
  50.  
  51. void
  52. SRGP_enableBlockedWait ()
  53. {
  54.    srgp__blockedWaitEnabled = TRUE;
  55. }
  56.  
  57.  
  58.  
  59. static void
  60. InitSRGP (char *name, int width, int height, int requested_planes, boolean debugasap)
  61. {
  62.    register cnt;
  63.    
  64.    
  65.    unlink ("./SRGPlogfile");
  66.  
  67.    ALLOC_RECORDS (srgp__bitmapPatternTable, pattern_table_entry, MAX_PATTERN_INDEX+1);
  68.    ALLOC_RECORDS (srgp__pixmapPatternTable, pixpat_table_entry, MAX_PATTERN_INDEX+1);
  69.    ALLOC_RECORDS (srgp__fontTable, fontInfo, MAX_FONT_INDEX+1);
  70.    ALLOC_RECORDS (srgp__cursorTable, cursorInfo, MAX_CURSOR_INDEX+1);
  71.    ALLOC_RECORDS (srgp__canvasTable, canvas_spec, MAX_CANVAS_INDEX+1);
  72. #ifdef X11
  73.    ALLOC_RECORDS (Xformat_vertices, XPoint, MAX_POINTLIST_SIZE);
  74. #endif
  75.  
  76.    
  77.    srgp__curActiveCanvasId = 0;
  78.    srgp__curActiveCanvasSpec.max_xcoord = (width-1);
  79.    srgp__curActiveCanvasSpec.max_ycoord = (height-1);
  80.    
  81.    SRGP__initGraphicsDevice (name, requested_planes, debugasap);
  82.  
  83.  
  84.    /*************** INIT. CANVAS TABLE TO SHOW THAT ONLY CANVAS 0 IS ALIVE */
  85.    srgp__canvasTable[0].drawable = srgp__curActiveCanvasSpec.drawable;
  86.    for (cnt=1; cnt <= MAX_CANVAS_INDEX; cnt++)
  87.       srgp__canvasTable[cnt].drawable.win = NULL;
  88.       
  89.    
  90.    SRGP__initCursorTable();
  91.  
  92.    SRGP__initDefaultPatterns();
  93.  
  94.    SRGP__initFont();
  95.  
  96.    SRGP__setCanvasDefaults();
  97.  
  98.    srgp__resizeCallback = NULL;
  99.  
  100.    /* INIT TRACING ET.AL. */
  101.    srgp__traceDisabled = TRUE;
  102.    SRGP_logStream = NULL;
  103.  
  104.    SRGP__initInputModule();
  105. }
  106.  
  107.  
  108.  
  109.  
  110. /*!*/
  111. void SRGP_beginWithDebug 
  112.    (char *name, int width, int height, int planes, boolean enable_trace)
  113. /* FOR USE BY SYSTEM ADMINS ONLY */
  114. {
  115.    if (srgp__enabled)
  116.       SRGP__error (ERR_ALREADY_ENABLED);
  117.    else {
  118.       srgp__enabled = TRUE;
  119.       InitSRGP (name, width, height, planes, TRUE);
  120.    }
  121.  
  122.    if (enable_trace) 
  123.       SRGP_tracing (TRUE);
  124. }
  125.  
  126.  
  127. /*!*/
  128. void SRGP_begin 
  129.    (char *name, int width, int height, int planes, boolean enable_trace)
  130. {
  131.    if (srgp__enabled)
  132.       SRGP__error (ERR_ALREADY_ENABLED);
  133.    else {
  134.       srgp__enabled = TRUE;
  135.       InitSRGP (name, width, height, planes, FALSE);
  136.    }
  137.  
  138.    if (enable_trace) 
  139.       SRGP_tracing (TRUE);
  140. }
  141.  
  142.  
  143. /*!*/
  144. void SRGP_registerResizeCallback (funcptr resizeCall)
  145. {
  146.    srgp__resizeCallback = resizeCall;
  147. }
  148.  
  149.  
  150.  
  151. /*!*/
  152. void SRGP_end ()
  153. {
  154.    SRGP_trace (SRGP_logStream, "SRGP_end\n");
  155.    
  156. #  ifdef THINK_C
  157.    SRGP__cleanupMacMemory();
  158.    DisposeWindow (srgpmac__cwindow);
  159. #  endif
  160.  
  161.    srgp__enabled = FALSE;
  162.    if (SRGP_logStream)
  163.       fclose (SRGP_logStream);
  164. }
  165.  
  166.  
  167.  
  168. void SRGP_setErrorHandlingMode (errorHandlingMode newmode)
  169. {
  170.    srgp__curErrHndlMode = newmode;
  171. }
  172.  
  173.  
  174. /** ROUTINES ALLOWING APPLICATION TO CHANGE SIZES OF TABLES
  175. These may only be called *before* SRGP is enabled.
  176. **/
  177.  
  178. static boolean CheckNotEnabledYet (void)
  179. {
  180.    if (srgp__enabled) {
  181.       SRGP__error (ERR_ALREADY_ENABLED);
  182.       return FALSE;
  183.    }
  184.    else
  185.       return TRUE;
  186. }
  187.  
  188.  
  189. void SRGP_setMaxCanvasIndex (int i)
  190. {
  191. if (CheckNotEnabledYet())
  192.    MAX_CANVAS_INDEX = i;
  193. }
  194.  
  195. void SRGP_setMaxPatternIndex (int i)
  196. {
  197. if (CheckNotEnabledYet())
  198.    MAX_PATTERN_INDEX = i;
  199. }
  200.  
  201. void SRGP_setMaxCursorIndex (int i)
  202. {
  203. if (CheckNotEnabledYet())
  204.    MAX_CURSOR_INDEX = i;
  205. }
  206.  
  207. void SRGP_setMaxFontIndex (int i)
  208. {
  209. if (CheckNotEnabledYet())
  210.    MAX_FONT_INDEX = i;
  211. }
  212.  
  213. void SRGP_setMaxPointlistSize (int i)
  214. {
  215. if (CheckNotEnabledYet())
  216.    MAX_POINTLIST_SIZE = i;
  217. }
  218.  
  219. void SRGP_setMaxStringSize (int i)
  220. {
  221. if (CheckNotEnabledYet())
  222.    MAX_STRING_SIZE = i;
  223. }
  224.  
  225.  
  226.  
  227. void
  228. SRGP__reactToScreenResize (int www, int hhh)
  229. {
  230.    if (srgp__curActiveCanvasId == 0)
  231.       srgp__canvasTable[0] = srgp__curActiveCanvasSpec;
  232.  
  233.    srgp__canvasTable[0].max_xcoord = www - 1;
  234.    srgp__canvasTable[0].max_ycoord = hhh - 1;
  235.  
  236.    if (srgp__curActiveCanvasId == 0)
  237.       srgp__curActiveCanvasSpec = srgp__canvasTable[0];
  238.    
  239.    /* The locator measure needs to be updated, since its y coord is a
  240.       function of the max_ycoord of the screen canvas. */
  241.    srgp__cur_locator_measure.position.y =
  242.       srgp__canvasTable[0].max_ycoord - srgp__cur_Xcursor_y;
  243.    
  244.    if (srgp__resizeCallback)
  245.       (*srgp__resizeCallback) (www, hhh);
  246. }
  247.  
  248.  
  249. void
  250. SRGP_changeScreenCanvasSize (int newwidth, int newheight)
  251. {
  252.    SRGP__forceScreenResize (newwidth, newheight);
  253.    SRGP__reactToScreenResize (newwidth, newheight);
  254. }
  255.